package com.chen.scaffolding.nacosserver.service.impl;

import com.chen.scaffolding.nacosconfig.entity.Authority;
import com.chen.scaffolding.nacosserver.entity.UserEntity;
import com.chen.scaffolding.nacosserver.mapper.UserMapper;
import com.chen.scaffolding.nacosserver.service.UserService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户类
 * @author :master
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private OpenFeignAuthorityService authorityService;

    @Autowired
    private UserMapper userMapper;

    @Override
    @GlobalTransactional(rollbackFor = Exception.class)
    @Transactional(rollbackFor = Exception.class)
    public void addUser(UserEntity userEntity) {
        // 第一步
        userMapper.addUser(userEntity);

        // 第二步
        Authority authority = new Authority();
        authority.setAuthId("1");
        authority.setAuthName("增加权限");
        authority.setUserId("1");
        authorityService.addAuthority(authority);
    }

    @Override
    public void updateUser(UserEntity userEntity) {
        userMapper.updateUser(userEntity);
    }
}
